#include<iostream>
#include<map>
using namespace std;

int main(){
	freopen("input.txt","r",stdin);
	int n;cin>>n;
	map<int,string> m1;
	map<int,int> m2;
	while(n--){
		int ji,zuo;
		string s;
		cin>>s>>ji>>zuo;
		m1[ji]=s;m2[ji]=zuo;
	}
	int m;cin>>m;
	while(m--){
		int t;cin>>t;
		cout<<m1[t]<<" "<<m2[t]<<endl;
	}
	return 0;
}